package com.mf.controller;


import com.mf.groups.GroupsAddInterface;
import com.mf.groups.GroupsUpdateInterface;
import com.mf.result.Result;
import com.mf.service.ServiceRiveDetail;
import com.mf.utils.UtilConverter;
import com.mf.entity.req.publicReq.ReqPublicIds;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.mf.entity.dto.DtoRive;
import com.mf.entity.req.ReqRive;
import com.mf.service.ServiceRive;
import com.mf.entity.req.search.SearchReqRive;

import java.util.List;

/**
 * 撕碎工单
 */
@RestController
@RequestMapping("rive")
@Tag(name = "撕碎工单")
public class ControllerRive {
    @Resource
    private ServiceRive servicerive;

    @Resource
    private ServiceRiveDetail serviceRiveDetail;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    public Result<Page<DtoRive>> findPage(@RequestBody SearchReqRive searchReqRive) {
        return Result.success(servicerive.findPageByParams(searchReqRive));
    }

    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public Result<List<DtoRive>> list(@RequestBody SearchReqRive searchReqRive) {
        return Result.success(servicerive.findListByParams(searchReqRive));
    }

    @Operation(summary = "保存")
    @PostMapping("/save")
    @Transactional
    public Result<Void> save(@Validated(GroupsAddInterface.class) @RequestBody ReqRive reqRive) {
        DtoRive dtoRive =  servicerive.saveRive(UtilConverter.convert(reqRive, DtoRive.class));
        serviceRiveDetail.saveDetail(reqRive.getIds(), dtoRive.getId(), reqRive.getSourceId(), reqRive.getWorkSource());
        return Result.success();
    }


    @Operation(summary = "删除")
    @PostMapping("/delete/{id}")
    public Result<Void> delete(@PathVariable("id") Integer id) {
        servicerive.removeById(id);
        return Result.success();
    }

}
